package a07_二叉树;

/**
 * <p>
 * a33_把二叉搜索树转换为累加树复习1
 * </p>
 *
 * @author flyduck
 * @since 2024-12-29
 */
public class a33_把二叉搜索树转换为累加树复习1 {

    private int prevValue = 0;

    public TreeNode convertBST(TreeNode root) {
        if (root == null) {
            return null;
        }

        convertBST(root.right);

        root.val = root.val + prevValue;
        prevValue = root.val;

        convertBST(root.left);
        return root;
    }
}
